<?php
@session_start();
date_default_timezone_set('UTC');
if(!isset($_SESSION['type_id']) || !isset($_SESSION['u_id']))
{
	header("Location:index.php");
	exit();
}
else
{
	$urlarray=explode("/",$_SERVER['PHP_SELF']);
	$phpselfname=$urlarray[count($urlarray)-1];
}


include_once "lib/pdomanager.php";

include_once "lib/functions.php";

DB::$dbname=DBNAME;
DB::$hostname=HOST;
DB::$dbusername=USERNAME;
DB::$dbpassword=PASSWORD;
DB::$dbtype=TYPE;
DB::$portnumber=PORTNUMBER;

DB::connect();

######################## Fetching Logged in User Records ###################

$user_details=DB::fetch_array(DB::query("select users.*,user_type from users,user_types where users.type_id=user_types.id and users.id='".$_SESSION['u_id']."' "));

//$systemsettings=DB::fetch_array(DB::query("select * from settings "));

function checkpermissions($arr,$value)
{
	foreach($arr as $key=>$val)
	{
		foreach($val as $keynew=>$val_new)
		{
			if($val_new==$value)
			{
				
				return true;
			}
		}
	}
	return false;
}

function checktabpermission($arr,$value)
{
	foreach($arr as $keynew=>$val_new)
	{
		if($val_new==$value)
		{
			
			return true;
		}
	}
	
	return false;
}

if(!checkpermissions($access_matrix[$user_details[0]['user_type']],$phpselfname))
{
	header("Location:no_access_level.php");
	exit();
}

if($_SESSION['type_id']==2)
{
	$unknown_image="images/admin.jpg";
}
else
{
	$unknown_image="images/no_image_boy.gif";
	if(isset($user_details[0]['gender']) && $user_details[0]['gender']!=Null){
		if($user_details[0]['gender']=="Male")
			$unknown_image="images/no_image_boy.gif";
		else
			$unknown_image="images/no_image_girl.gif";	
	}
}

$defaultcurrency="Rs.";

?>
<!DOCTYPE html>
<html >
	<head>
		<meta http-equiv="content-type" content="text/html; charset=utf-8" />
		<title>Allyfolio Admin Portal</title>
       
        <!-- CSS Reset -->
		<link rel="stylesheet" type="text/css" href="css/reset.css" media="screen" />
       
        <!-- Fluid 960 Grid System - CSS framework -->
		<link rel="stylesheet" type="text/css" href="css/grid.css" media="screen" />
		
        <!-- IE Hacks for the Fluid 960 Grid System -->
        <!--[if IE 6]><link rel="stylesheet" type="text/css" href="ie6.css" tppabs="http://www.xooom.pl/work/magicadmin/css/ie6.css" media="screen" /><![endif]-->
		<!--[if IE 7]><link rel="stylesheet" type="text/css" href="ie.css" tppabs="http://www.xooom.pl/work/magicadmin/css/ie.css" media="screen" /><![endif]-->
        
        <!-- Main stylesheet -->
        <link rel="stylesheet" type="text/css" href="css/styles.css" media="screen" />
        
        <!-- Thickbox stylesheet -->
        <link rel="stylesheet" type="text/css" href="css/thickbox.css" media="screen" />
        
        <!-- Themes. Below are several color themes. Uncomment the line of your choice to switch to different color. All styles commented out means blue theme. -->
        <link rel="stylesheet" type="text/css" href="css/theme-blue.css" media="screen" />
        
        <!-- The below two css are used for notifications -->
        <link rel="stylesheet" type="text/css" href="css/jquery.noty.css" media="screen" />
        <link rel="stylesheet" type="text/css" href="css/noty_theme_default.css" media="screen" />
        
		<!-- JQuery engine script-->
		<script type="text/javascript" src="js/jquery-1.3.2.min.js" ></script>
        
		<!-- JQuery password strength plugin script -->
		<script type="text/javascript" src="js/jquery.pstrength-min.1.2.js"></script>
        
		<!-- JQuery thickbox plugin script -->
		<script type="text/javascript" src="js/thickbox.js"></script>
        
        <!-- General All pages javascript -->
        <script type="text/javascript" src="js/general.js" ></script>
        
        <!-- Below two js are used for notifications -->
        <?php
        if(!strstr($phpselfname,"change_pwd.php"))
        {
        ?>
        <script type="text/javascript" src="js/jquery-1.7.2.min.js" ></script>
		<script type="text/javascript" src="js/jquery.noty.js"></script>
		
        <?php
        }
        ?>
        <!-- Initiate WYIWYG text area -->
		
        <script src="js/jquery.titlealert.js"></script>
  <style>



</style>      
        
        <link rel="stylesheet" href="alertify/themes/alertify.core.css" />
		 <link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
		 <script src="alertify/lib/alertify.min.js"></script>	
		 
		<script type="text/javascript" src="js/sensor.js"></script>
         	
	</head>
	<body>
    	<!-- Header -->
    	<div id="header">
            <!-- Header. Status part -->
            <div id="header-status">
                <div class="container_12">
                    <div class="grid_8" style="margin-top: 10px;">
						<a href="dashboard.php"><img src="../images/logo.png"></a>
                    </div>
                    <div class="grid_4">
                    	<a href="logout.php" id="logout" style="float:right;">
                        Logout
                        </a>
                    	<span style="float:right;padding-top:9px;padding-right:9px;"><b>Welcome <?php echo $user_details[0]['full_name']; ?></b></span>
                    	
                        
                    </div>
                </div>
                <div style="clear:both;"></div>
            </div> <!-- End #header-status -->
            
            <!-- Header. Main part -->
            <div id="header-main">
                <div class="container_12">
                    <div class="grid_12">
                        <div id="logo">
                            
                            	<ul id="menu" class="nav">
                            		<?php
                            		foreach($access_matrix[$user_details[0]['user_type']] as $key=>$val)
                            		{
                            			$phpexistsflag=false;
                            			$phpexistsflag=checktabpermission($val,$phpselfname);
                            			
                            				?>
                            				<li class="navli" <?php if($phpexistsflag==true){ ?>id="current"<?php } ?> >
					                        	<a href="<?php echo $val[0]; ?>" class="navlia"  <?php if($phpexistsflag==true){ ?>id="navlicurrenta"<?php } ?> ><?php echo $key ?></a>
					                        	<ul class="fulli">
					                        	<?php
					                        	foreach($val as $keysubname=>$valsublink)
					                        	{
					                        		if(!is_numeric($keysubname) && $valsublink!="no_access_level.php" && !strstr($valsublink,"view_")  && !strstr($valsublink,"addedit_") && !strstr($valsublink,"dashboard") && !strstr($valsublink,"edit_"))
					                        		{
														?>
														<li>
															<a href="<?php echo $valsublink; ?>"><?php echo $keysubname; ?></a>
														</li>
														<?php
													}
												}
					                        	?>
					                        	</ul>
					                        	
																				
					                        	
                            				<?php
											
									}
                            		?>
       							 
					        </ul>
                        </div><!-- End. #Logo -->
                    </div><!-- End. .grid_12-->
                    <div style="clear: both;"></div>
                </div><!-- End. .container_12 -->
            </div> <!-- End #header-main -->
            <div style="clear: both;"></div>
            <!-- Sub navigation -->
             <!-- End #subnav -->
        </div> <!-- End #header -->